# 操作excel
import xlrd

# 1.先打开xls文件.
xls = xlrd.open_workbook("e:/python_code/test.xls")
# 2.获取到指定的标签页(例如Sheet1)
table = xls.sheet_by_index(0)
# 3.获取到表格中有多少行
nrows = table.nrows
# print(f'nrows = {nrows}')
# 4.进行循环统计操作
total = 0
count = 0
for i in range(1, nrows):
    # 拿到当前同学的班级id
    # print('---------------------')
    # print(table.cell_value(i, 0)) # 姓名
    # print(table.cell_value(i, 1)) # 班级
    # print(table.cell_value(i, 2)) # 成绩
    classId = table.cell_value(i, 1)
    if classId == 1:
        total += table.cell_value(i, 2)
        count += 1
print(f'平均分 = {total/count}')






